/* ================================================================================ *//**
 \license     %LICENSE%
 \file        rtos_tasks.c
 \author      ukasz Krzak
 \purpose     STM32 RTOS demo application
 \compiler    %COMPILER%
 \hardware    independent
 \doc         doxygen
 \brief       RTOS task definitions
 \comments
*//* ================================================================================= */

#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include "stm32f10x.h"
//#include "stm32f10x_conf.h"
#include <stdio.h>

// -----------------------------------------------------------------------------
//  TASK_LED1
//
//  This task simply blinks a LED
// -----------------------------------------------------------------------------
void TASK_LED1( void* pvParameters )
{

    // dummy instruction to avoid compiler warnings
    (void) pvParameters;

    printf("LED Task\r\n");
	GPIO_InitTypeDef GPIO_InitStructure;

	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
	/**
	 *	LED1 -> PB0   LED2 -> PB1
	 */
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
	GPIO_Init(GPIOB, &GPIO_InitStructure);

    while (1) {
        GPIO_SetBits(GPIOB, GPIO_Pin_0);
        vTaskDelay(1000);
        GPIO_ResetBits(GPIOB, GPIO_Pin_0);
        vTaskDelay(1000);
    }
} /* TASK_LED1 */


// -----------------------------------------------------------------------------
//  TASK_USART
//
//  This task simply blinks a LED
// -----------------------------------------------------------------------------
void TASK_USART(void* pvParameters)
{
    extern xSemaphoreHandle sem;

    while (1) {
        if (NULL != sem) {
            if (pdTRUE == xSemaphoreTake(sem, 1000)) {
                printf("Hello World\r\n");
                xSemaphoreGive(sem);
            }
        }

        vTaskDelay(100);
    }

} /* TASK_USART */
